home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / PublicDomain / Anwendungen / LimitWhite / Source / Patch.C < prev    next >
C/C++ Source or Header  |  2000-03-16  |  10KB  |  314 lines

  1. /* ------------------------------------------------------------------------------------------------------------ */
  2. /*                                                                                                              *
  3.  *   LimitWhite V1.0 OS Patch Functions
  4.  *                                                                                                              */
  5. /* ------------------------------------------------------------------------------------------------------------ */
  6.  
  7. #include "Patch.h"
  8. #include "globals.h"
  9.  
  10. /* ------------------------------------------------------------------------------------------------------------ */
  11.  
  12. void LoadRGB32Patched(register __a0 struct ViewPort *Param1, register __a1 ULONG *Param2, register __a6 struct Library *Param3)
  13. {
  14.     UWORD numcolours, loop;
  15.  
  16.     /* Patched LoadRGB32() function */
  17.  
  18.     if (Param2)
  19.     {
  20.         /* Search for full whites and reduce them */
  21.  
  22.         numcolours = Param2[0] >> 16;
  23.  
  24.         for (loop = 0; loop < numcolours; loop++)
  25.         {
  26.             if (Param2[(loop * 3) + 1] >> 24 == 0xff)
  27.             {
  28.                 if (Param2[(loop * 3) + 2] >> 24 == 0xff)
  29.                 {
  30.                     if (Param2[(loop * 3) + 3] >> 24 == 0xff)
  31.                     {
  32.                         /* Found full white. Reduce it */
  33.  
  34.                         Param2[(loop * 3) + 1] = 0xf5ffffff;
  35.                         Param2[(loop * 3) + 2] = 0xf5ffffff;
  36.                         Param2[(loop * 3) + 3] = 0xf5ffffff;
  37.                     } /* if */
  38.                 } /* if */
  39.             } /* if */
  40.         } /* for */
  41.     } /* if */
  42.  
  43.     /* Now call the original function */
  44.  
  45.     LoadRGB32Bak(Param1, Param2, Param3);
  46. } /* LoadRGB32Patched() */
  47.  
  48. /* ------------------------------------------------------------------------------------------------------------ */
  49.  
  50. void LoadRGB4Patched(register __a0 struct ViewPort *Param1, register __a1 UWORD *Param2, register __d0 WORD Param3, register __a6 struct Library *Param4)
  51. {
  52.     static UWORD loop;
  53.  
  54.     /* Patched LoadRGB4() function */
  55.  
  56.     if (Param2)
  57.     {
  58.         /* Search for full whites and reduce them */
  59.  
  60.         for (loop = 0; loop < Param3; loop++)
  61.         {
  62.             if (Param2[loop] == 0x0fff)
  63.             {
  64.                 /* Full white. Reduce */
  65.  
  66.                 Param2[loop] = 0x0eee;
  67.             } /* if */
  68.         } /* loop */
  69.     } /* if */
  70.  
  71.     /* Now call the original function */
  72.  
  73.     LoadRGB4Bak(Param1, Param2, Param3, Param4);
  74. } /* LoadRGB4Patched() */
  75.  
  76. /* ------------------------------------------------------------------------------------------------------------ */
  77.  
  78. void SetRGB32Patched(register __a0 struct ViewPort *Param1, register __d0 ULONG Param2, register __d1 ULONG Param3, register __d2 ULONG Param4, register __d3 ULONG Param5, register __a6 struct Library *Param6)
  79. {
  80.     /* Patched SetRGB32() function */
  81.  
  82.     /* If colour is full white, reduce it */
  83.  
  84.     if ((Param3 >> 24) == 0xff)
  85.     {
  86.         if ((Param4 >> 24) == 0xff)
  87.         {
  88.             if ((Param5 >> 24) == 0xff)
  89.             {
  90.                 Param3 = 0xf5000000;
  91.                 Param4 = 0xf5000000;
  92.                 Param5 = 0xf5000000;
  93.             } /* if */
  94.         } /* if */
  95.     } /* if */
  96.  
  97.     /* Now call the original function */
  98.  
  99.     SetRGB32Bak(Param1, Param2, Param3, Param4, Param5, Param6);
  100. } /* SetRGB32Patched() */
  101.  
  102. /* ------------------------------------------------------------------------------------------------------------ */
  103.  
  104. void SetRGB32CMPatched(register __a0 struct ColorMap *Param1, register __d0 ULONG Param2, register __d1 ULONG Param3, register __d2 ULONG Param4, register __d3 ULONG Param5, register __a6 struct Library *Param6)
  105. {
  106.     /* Patched SetRGB32CM() function */
  107.  
  108.     /* If colour is full white, reduce it */
  109.  
  110.     if ((Param3 >> 24) == 0xff)
  111.     {
  112.         if ((Param4 >> 24) == 0xff)
  113.         {
  114.             if ((Param5 >> 24) == 0xff)
  115.             {
  116.                 Param3 = 0xf5000000;
  117.                 Param4 = 0xf5000000;
  118.                 Param5 = 0xf5000000;
  119.             } /* if */
  120.         } /* if */
  121.     } /* if */
  122.  
  123.     /* Now call the original function */
  124.  
  125.     SetRGB32CMBak(Param1, Param2, Param3, Param4, Param5, Param6);
  126. } /* SetRGB32CMPatched() */
  127.  
  128. /* ------------------------------------------------------------------------------------------------------------ */
  129.  
  130. void SetRGB4Patched(register __a0 struct ViewPort *Param1, register __d0 SHORT Param2, register __d1 UBYTE Param3, register __d2 UBYTE Param4, register __d3 UBYTE Param5, register __a6 struct Library *Param6)
  131. {
  132.     /* Patched SetRGB4() function */
  133.  
  134.     /* If colour is full white, then reduce it */
  135.  
  136.     if (Param3 == 15)
  137.     {
  138.         if (Param4 == 15)
  139.         {
  140.             if (Param5 == 15)
  141.             {
  142.                 /* Reduce white */
  143.  
  144.                 Param3 = 14;
  145.                 Param4 = 14;
  146.                 Param5 = 14;
  147.             } /* if */
  148.         } /* if */
  149.     } /* if */
  150.  
  151.     /* Now call the original function */
  152.  
  153.     SetRGB4Bak(Param1, Param2, Param3, Param4, Param5, Param6);
  154. } /* SetRGB4Patched() */
  155.  
  156. /* ------------------------------------------------------------------------------------------------------------ */
  157.  
  158. void SetRGB4CMPatched(register __a0 struct ColorMap *Param1, register __d0 SHORT Param2, register __d1 UBYTE Param3, register __d2 UBYTE Param4, register __d3 UBYTE Param5, register __a6 struct Library *Param6)
  159. {
  160.     /* Patched SetRGB4CM() function */
  161.  
  162.     /* If colour is full white, then reduce it */
  163.  
  164.     if (Param3 == 15)
  165.     {
  166.         if (Param4 == 15)
  167.         {
  168.             if (Param5 == 15)
  169.             {
  170.                 /* Reduce white */
  171.  
  172.                 Param3 = 14;
  173.                 Param4 = 14;
  174.                 Param5 = 14;
  175.             } /* if */
  176.         } /* if */
  177.     } /* if */
  178.  
  179.     /* Now call the original function */
  180.  
  181.     SetRGB4CMBak(Param1, Param2, Param3, Param4, Param5, Param6);
  182. } /* SetRGB4CMPatched() */
  183.  
  184. /* ------------------------------------------------------------------------------------------------------------ */
  185.  
  186. void InstallPatches()
  187. {
  188.     /* Install the OS patches */
  189.  
  190.     Forbid();
  191.  
  192.     LoadRGB32Bak =          SetFunction((struct Library *)GfxBase, -882, (void *)LoadRGB32Patched);
  193.     LoadRGB4Bak =           SetFunction((struct Library *)GfxBase, -192, (void *)LoadRGB4Patched);
  194.     SetRGB32Bak =           SetFunction((struct Library *)GfxBase, -852, (void *)SetRGB32Patched);
  195.     SetRGB32CMBak =         SetFunction((struct Library *)GfxBase, -996, (void *)SetRGB32CMPatched);
  196.     SetRGB4Bak =            SetFunction((struct Library *)GfxBase, -288, (void *)SetRGB4Patched);
  197.     SetRGB4CMBak =          SetFunction((struct Library *)GfxBase, -630, (void *)SetRGB4CMPatched);
  198.  
  199.     Permit();
  200. } /* InstallPatches() */
  201.  
  202. /* ------------------------------------------------------------------------------------------------------------ */
  203.  
  204. BOOL RemovePatches()
  205. {
  206.     void *functionptr;
  207.  
  208.     /* Remove the OS patches */
  209.  
  210.     /* This is difficult, and can be dangerous. I'm using a method suggested in the SaferPatches text (on AFCD48)
  211.        to attempt to remove the patches. If it fails, this function returns FALSE and keeps all patches installed.
  212.        If it succeeds, all the patches are removed and TRUE is returned. Installing SaferPatches will increase the
  213.        chance of the patches being removed successfully */
  214.  
  215.     /* Check each patch in turn */
  216.  
  217.     Forbid();
  218.  
  219.     functionptr = SetFunction((struct Library *)GfxBase, -882, (void *)LoadRGB32Patched);
  220.  
  221.     if (functionptr != LoadRGB32Patched)
  222.     {
  223.         /* A patch has been installed over the top of our patch. We can't kill the program */
  224.  
  225.         SetFunction((struct Library *)GfxBase, -882, functionptr);
  226.  
  227.         Permit();
  228.  
  229.         return(FALSE);
  230.     } /* if */
  231.  
  232.     functionptr = SetFunction((struct Library *)GfxBase, -192, (void *)LoadRGB4Patched);
  233.  
  234.     if (functionptr != LoadRGB4Patched)
  235.     {
  236.         /* A patch has been installed over the top of our patch. We can't kill the program */
  237.  
  238.         SetFunction((struct Library *)GfxBase, -192, functionptr);
  239.  
  240.         Permit();
  241.  
  242.         return(FALSE);
  243.     } /* if */
  244.  
  245.     functionptr = SetFunction((struct Library *)GfxBase, -852, (void *)SetRGB32Patched);
  246.  
  247.